<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Medknow Intranet</title>
    </h:head>
    <h:body>
        <ui:composition template="medKnowTemplate.xhtml">
            <ui:define name="left">
                <h:form id="Menu">
                    <h:commandLink rendered="${user.showAppointmentMenu()}"
                                   action="${user.showAppointment()}" id="appointment">
                        <h1>Appointment</h1><br/>
                        <f:ajax execute="appointment" render="Menu"/>
                    </h:commandLink>

                    <h:commandLink rendered="${user.showPatientManagmentMenu()}"
                                   action="${user.showPatientManagment()}" id="patientManagment">
                        <h1>Patient Management</h1><br/>
                        <f:ajax execute="patientManagment" render="Menu"/>
                    </h:commandLink>

                    <h:commandLink rendered="${user.showDoctorManagmentMenu()}"
                                   action="${user.showDoctorManagment()}" id="doctorManagment">
                        <h1>Doctor Management</h1><br/>
                        <f:ajax execute="doctorManagment" render="Menu"/>
                    </h:commandLink>

                    <h:commandLink rendered="${user.showScheduleMenu()}"
                                   action="${user.showSchedule()}" id="schedule">
                        <h1>Check Schedule</h1><br/>
                        <f:ajax execute="schedule" render="Menu"/>
                    </h:commandLink>

                    <h:commandLink rendered="${user.showUserAddManagmentMenu()}"
                                   action="${user.showUserAddManagment()}" id="userAdd">
                        <h1>User Management</h1>
                        <f:ajax execute="userAdd" render="Menu"/>
                    </h:commandLink>
                </h:form>
            </ui:define>

            <ui:define name="content">
                <h:form id="Managment">
                    <h:panelGrid columns="1"  width="30%">
                        <h:panelGroup rendered="${user.appointment}">
                            <h3>Appointment</h3>
                            <h:outputText value="Do you want to delete or add a Appointment"></h:outputText>
                            <h:selectOneRadio value="${select.radioA}" id="radioA">
                                <f:selectItem itemValue="add" itemLabel="Add"/>
                                <f:selectItem itemValue="delete" itemLabel="Delete"/>
                                <f:ajax execute="radioA" render="Managment"/>
                            </h:selectOneRadio>

                            <h:panelGrid columns="${validate.column}"
                                         bgcolor="#eff5fa" 
                                         title="Appointment" border="1" width="100%">
                                <h:outputText value='Select a Doctor'></h:outputText>
                                <h:selectOneMenu value="${select.selectedDoctors}">
                                    <f:selectItems value="${select.selectDoctors}"/>
                                </h:selectOneMenu>
                                <h:outputLabel rendered="${validate.render}" style="color:green" value="*"/>

                                <h:outputText value="Select a Patient"/>
                                <h:selectOneMenu value="${select.selectedPatient}">
                                    <f:selectItems value="${select.selectPatient}"/>
                                </h:selectOneMenu>
                                <h:outputLabel rendered="${validate.render}" style="color:green" value="*"/>

                                <h:outputText value="Date(${select.dateFormatAsString}):"></h:outputText>
                                <h:inputText value="${select.appointmentDate}" validator="${validate.validateDate}" id="date" required="true" requiredMessage="Date is required"/>
                                <h:message for="date" style="color:red" rendered="${validate.render}"/>
                            </h:panelGrid>
                            <h:messages style="color:red" />
                            <h:panelGrid columns="4"
                                         bgcolor="#eff5fa" rendered="${select.appointmentAdd}"
                                         title="Appointment" border="1" width="100%">
                                <h:outputText value='Astigmatic'></h:outputText>
                                <h:inputText value="${select.appointmentAstigmatic}"/>
                                <h:outputText value="Tear rate"/>
                                <h:inputText value="${select.appointmentTearRate}"/>
                                <h:outputText value='Prescription'></h:outputText>
                                <h:inputText value="${select.appointmentPrescription}"/>
                                <h:outputText value='Lenses'></h:outputText>
                                <h:inputText value="${select.appointmentLenses}"/>
                            </h:panelGrid>
                            <h:commandButton rendered="${select.appointmentAdd}" value="Add appointment" action="${select.submitAddAppointment}"/>
                            <h:commandButton rendered="${select.appointmentAdd}" value="Update appointment" action="${select.submitUpdateAppointment}"/>
                            <h:commandButton rendered="${!select.appointmentAdd}" value="Remove appointment" action="${select.submitDeleteAppointment}"/>
                        </h:panelGroup>

                        <h:panelGroup rendered="${user.doctorManagment}">
                            <h3>Doctor managment</h3>
                            <h:outputText value="Do you want to delete or add a Doctor"></h:outputText>
                            <h:selectOneRadio value="${select.radioD}" id="radioD">
                                <f:selectItem itemValue="add" itemLabel="Add"/>
                                <f:selectItem itemValue="delete" itemLabel="Delete"/>
                                <f:ajax execute="radioD" render="Managment"/>
                            </h:selectOneRadio>
                            <h:outputText rendered="${select.doctorAdd}" value="Doctor adding"></h:outputText>
                            <h:panelGroup rendered="${select.doctorAdd}">
                                <h:panelGrid columns="2"
                                             rendered="${user.isAdmin}" bgcolor="#eff5fa"
                                             title="Appointment" border="1" width="100%">
                                    <h:outputText value='Filial:'></h:outputText>
                                    <h:selectOneMenu value="${select.selectedFilial}">
                                        <f:selectItems value="${select.selectFilial}"/>
                                    </h:selectOneMenu>
                                    <h:outputText value='Name:'></h:outputText>
                                    <h:inputText required="true" value="${select.doctorName}" requiredMessage="Name is required"/>
                                </h:panelGrid>
                                <h:messages style="color:red"/>
                                <h:commandButton value="Add a doctor" action="${select.submitAddDoctor}"/>
                            </h:panelGroup>

                            <h:outputText rendered="${!select.doctorAdd}" value="Doctor deleting"></h:outputText>
                            <h:panelGroup rendered="${!select.doctorAdd}">
                                <h:panelGrid columns="2"
                                             rendered="${user.isAdmin}" bgcolor="#eff5fa"
                                             title="Appointment" border="1" width="100%">
                                    <h:outputText value='Select a Doctor ID'></h:outputText>
                                    <h:selectOneMenu value="${select.selectedDoctors}">
                                        <f:selectItems value="${select.selectDoctors}"/>
                                    </h:selectOneMenu>
                                </h:panelGrid>
                                <h:commandButton value="Delete a doctor" action="${select.submitDeleteDoctor()}"/>
                            </h:panelGroup>
                        </h:panelGroup>

                        <h:panelGroup rendered="${user.patientManagment}">
                            <h3>Patient managment</h3>
                            <h:outputText value="Do you want to delete or add a Patient"></h:outputText>
                            <h:selectOneRadio value="${select.radioP}" id="radioP">
                                <f:selectItem itemValue="add" itemLabel="Add"/>
                                <f:selectItem itemValue="delete" itemLabel="Delete"/>
                                <f:ajax execute="radioP" render="Managment"/>
                            </h:selectOneRadio>
                            <h:outputText rendered="${select.patientAdd}" value="Patient adding"></h:outputText>
                            <h:panelGroup rendered="${select.patientAdd}">
                                <h:panelGrid columns="${validate.column}" 
                                             rendered="${user.isAdmin}" bgcolor="#eff5fa"
                                             title="Pmanagment" border="1" width="100%">
                                    <h:outputText value='Name:'></h:outputText>
                                    <h:inputText value="${select.patientName}" required="true" requiredMessage="Name is required" id="patientNameInp"/> 
                                    <h:message for="patientNameInp" style="color:red" rendered="${validate.render}"/>

                                    <h:outputText value="Date of birth(${select.dateFormatAsString}):" />
                                    <h:inputText value="${select.patientDateOfBirth}" required="true" validator="${validate.validateDate}" id="dateOfBirth" requiredMessage="Date is required"/> 
                                    <h:message for="dateOfBirth" style="color:red" rendered="${validate.render}"/>
                                </h:panelGrid>
                                <h:messages rendered="${!validate.render}" style="color:red" />
                                <h:commandButton value="Add a patient" action="${select.submitAddPatient}"/>
                            </h:panelGroup>

                            <h:outputText rendered="${!select.patientAdd}" value="Patient deleting"></h:outputText>
                            <h:panelGroup rendered="${!select.patientAdd}">
                                <h:panelGrid columns="1"
                                             rendered="${user.isAdmin}" bgcolor="#eff5fa"
                                             title="Pmanagment" border="1" width="100%">
                                    <h:outputText value='Select a Patient ID'></h:outputText>
                                    <h:selectOneMenu value="${select.selectedPatient}">
                                        <f:selectItems value="${select.selectPatient}"/>
                                    </h:selectOneMenu>
                                </h:panelGrid>
                                <h:commandButton value="Delete a patient" action="${select.submitDeletePatient}"/>
                            </h:panelGroup>
                        </h:panelGroup>

                        <h:panelGroup rendered="${user.userAdd}">
                            <h3>User managment</h3>
                            <h:selectOneRadio value="${select.radioU}" id="radioU">
                                <f:selectItem itemValue="add" itemLabel="Add"/>
                                <f:selectItem itemValue="delete" itemLabel="Delete"/>
                                <f:ajax execute="radioU" render="Managment"/>
                            </h:selectOneRadio>

                            <h:panelGroup rendered="${select.userAdd}">
                                <h2>User adding</h2>
                                <h:panelGrid columns="3" width="100%">

                                    <h:outputText value="User login"></h:outputText>
                                    <h:inputText value="${select.userLogin}" id="user" requiredMessage="User name cannot be empty" required="true"/>
                                    <h:message for="user" rendered="true" style="color:red"/>

                                    <h:outputText value="User password"></h:outputText>
                                    <h:inputSecret value="${select.userPassword}" id="password" requiredMessage="Password cannot be empty" required="true"/>
                                    <h:message for="password" rendered="true" style="color:red"/>

                                    <h:selectOneMenu value="${select.selectedRole}">
                                        <f:selectItems value="${select.selectRole}"/>
                                    </h:selectOneMenu>                                
                                </h:panelGrid>
                                <h:commandButton value="Add/update" action="${select.submitAddUser}"/>
                            </h:panelGroup>

                            <h:panelGroup rendered="${!select.userAdd}">
                                <h2>User deleting</h2>
                                <h:panelGrid columns="2" width="100%">
                                    <h:outputText value="Select User to delete"></h:outputText>
                                    <h:selectOneMenu value="${select.selectedUser}">
                                        <f:selectItems value="${select.selectUser}"/>
                                    </h:selectOneMenu>      
                                </h:panelGrid>
                                <h:commandButton value="Remove" action="${select.submitDeleteUser}"/>
                            </h:panelGroup>

                        </h:panelGroup>

                        <h:panelGroup rendered="${user.schedule}">
                            <h3>Schedule</h3>
                            
                            <h:dataTable value="${hib.visits}" var="v" border="3">
                                <h:column>
    				<f:facet name="header">Doctor</f:facet>
    				#{v.doctor.name}
                                </h:column>
                                
                                <h:column>
    				<f:facet name="header">Patient</f:facet>
    				#{v.patient.name}
                                </h:column>
                                
                                <h:column>
    				<f:facet name="header">Datetime</f:facet>
    				#{v.date}
                                </h:column>
                                
                            </h:dataTable>
                        </h:panelGroup>

                    </h:panelGrid>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

